package com.lengyue.imakiba.manage;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.lengyue.imakiba.data.AnimeCV;
import com.lengyue.imakiba.data.CV;

public class AnimeCVManage extends Controller {
	public void index()
	{
		int animeId = Integer.parseInt(getPara("animeId"));
		List<CV> cvs = CV.dao.find("select c.* from cv c inner join anime_cv ac on c.id = ac.cv_id where ac.anime_id = ?",animeId);
		renderJson(cvs);
	}
	public static void updateCVByAnime(int animeId,String[] cvs)
	{
		deleteCVByAnime(animeId);
		addCVByAnime(animeId,cvs);
	}
	public static void addCVByAnime(int animeId,String[] cvs)
	{
		for(String cvId : cvs)
		{
			new AnimeCV().set("anime_id", animeId).set("cv_id", Integer.parseInt(cvId)).save();
		}
	}
	public static void deleteCVByAnime(int animeId)
	{
		Db.update("delete from anime_cv where anime_id = ?", animeId);
	}
}
